using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Text;
using System.Data.SqlClient;
using System.Diagnostics;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.ApplicationPages;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Utilities;

namespace TweakSP.Web.Admin
{
    public partial class TweakSP_AdminSettings : GlobalAdminPageBase
    {
        protected RadioButton databaseFunctionalityOn;
        protected RadioButton databaseFunctionalityOff;


        public override string PageToRedirectOnCancel
        {
            get
            {
                return "/_admin/TweakSP_Main.aspx";
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                this.InitPropertyValues();
            }
        }


        private void InitPropertyValues()
        {
            if (ContentService.TweakSP_ContentService.Local.DatabaseTweaksEnabled == true)
            {
                this.databaseFunctionalityOn.Checked = true;
            }
            else
            {
                this.databaseFunctionalityOff.Checked = true;
            }
        }

        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            if (!SPUtility.ValidateFormDigest())
            {
                throw new SPException(SPResource.GetString("PageSecurityValidationFailed", new object[0]));
            }
            if (this.Page.IsValid)
            {
                // Save the value
                this.SetConfigurationFromForm();

                SPUtility.Redirect("/_admin/TweakSP_Main.aspx", SPRedirectFlags.UseSource, this.Context);
            }

        }

        private void SetConfigurationFromForm()
        {
            ContentService.TweakSP_ContentService.Local.DatabaseTweaksEnabled = this.databaseFunctionalityOn.Checked;
        }


/*
        protected Button btnDatabaseFeatures;

        protected void Page_Load(object sender, EventArgs e)
        {
            btnDatabaseFeatures.Click += new EventHandler(btnDatabaseFeatures_Click);

            UpdateDatabaseFeaturesButton();

        }

        void btnDatabaseFeatures_Click(object sender, EventArgs e)
        {
            ContentService.TweakSP_ContentService.Local.DatabaseTweaksEnabled = !ContentService.TweakSP_ContentService.Local.DatabaseTweaksEnabled;
            UpdateDatabaseFeaturesButton();
        }

        void UpdateDatabaseFeaturesButton()
        {
            // Are Database Features enabled?
            if (ContentService.TweakSP_ContentService.Local.DatabaseTweaksEnabled)
            {
                btnDatabaseFeatures.Text = "Disable Database Features";
            }
            else
            {
                btnDatabaseFeatures.Text = "Enable Database Features";
            }
        }
*/
    }
}
